package fr.lille.inria.adam.lifl.EcoGardeInventory.Utils;

import java.io.IOException;
import java.util.List;

import android.util.Log;

import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;

public class GCM_MessageUtil {

	public static void sendMessageToGCM_ThenToDevice(String type,
			String api_key, String registrationId, String msg) {

		Sender sender = new Sender(api_key);
		Message message = new Message.Builder().addData(type, msg).build();
		// Message message = new
		// Message.Builder().collapseKey("1").timeToLive(3).delayWhileIdle(true).addData(type,
		// msg).build();
		try {
			Result result = sender.send(message, registrationId, 3);
			Log.d("GCM_MessageUtil_sendMessageToGCM_ThenToDevice(): ", "result.toString()..." + result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void sendMultipleMessagesToGCM_ThenToDevices(String type,
			String api_key, List<String> registrationIds, String msg) {

		Sender sender = new Sender(api_key);
		Message message = new Message.Builder().addData(type, msg).build();
		// Message message = new
		// Message.Builder().collapseKey("1").timeToLive(3).delayWhileIdle(true).addData(type,
		// msg).build();
		try {
			MulticastResult result = sender.send(message, registrationIds, 5);
			Log.d("GCM_MessageUtil_sendMultipleMessagesToGCM_ThenToDevices(): ", "result.toString()..." + result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
